package helexis.game.tyrian.screen;

import helexis.game.tyrian.Tyrian;
import helexis.game.tyrian.domain.Profile;
import helexis.game.tyrian.service.SoundManager.TyrianSound;

import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;

public class HighScoresScreen extends AbstractScreen {
	
	
	private Label episode1HighScore;
	private Label episode2HighScore;
	private Label episode3HighScore;
	
	
	public HighScoresScreen(Tyrian game) {
		super(game);
	}//end of constructor
	
	@Override
	public void show() {
		
		super.show();
		
		if (table == null) {
			this.init();
		}//end if
		
		Profile profile = game.getProfileManager().retrieveProfile();
		
		this.episode1HighScore.setText(String.valueOf(profile.getHighScore(0)));
		this.episode2HighScore.setText(String.valueOf(profile.getHighScore(1)));
		this.episode3HighScore.setText(String.valueOf(profile.getHighScore(2)));
		
	}//end of show()
	
	
	public void init() {
		
		Skin skin = getSkin();
		
		table = new Table(skin);
		table.setFillParent(true);
		stage.addActor(table);
		
		table.add("High Scores").colspan(2).spaceBottom(20);
		table.row();
		
		table.defaults().spaceBottom(10);
		
		
		table.add("Episode 1");
		
		this.episode1HighScore = new Label("", skin);
		table.add(this.episode1HighScore);		
		table.row();
		
		
		table.add("Episode 2");
		
		this.episode2HighScore = new Label("", skin);
		table.add(this.episode2HighScore);
		table.row();
		
		
		table.add("Episode 3");
		
		this.episode3HighScore = new Label("", skin);
		table.add(this.episode3HighScore);
		table.row();
		
		
		TextButton backButton = new TextButton("Back", skin);
		backButton.addListener(new ClickListener() {
			@Override
			public void clicked(InputEvent event, float x, float y) {
				game.getSoundManager().play(TyrianSound.CLICK);
				game.setScreen(game.getMenuScreen());
			}//end of clicked()
		});
		table.add(backButton).size(300, 60).colspan(2);
		
	}//end of init()
	

}
//end of HighScoresScreen.java
